package com.shuqi.model;

import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import android.content.Context;

import com.shuqi.common.MyTask;
import com.shuqi.common.Urls;
import com.shuqi.model.net.HttpRequest;
import com.shuqi.model.net.UrlManager;
import com.shuqi.model.net.listener.HttpRequestListener;
import com.shuqi.model.parse.parser.AccountRegisterParser;

/**
 * @author liyizhe 手机、邮箱注册获取数据
 */
public class AccountRegisterModel extends ModelBase implements HttpRequestListener {

    public static final String TYPE_REGISTER_PHOEN = "1";// 1表示手机号
    public static final String TYPE_REGISTER_EMAIL = "2";// 2表示邮箱

    private HttpRequest mHttpRequest;
    private Context mContext;
    List<BasicNameValuePair> params;

    public AccountRegisterModel(Context context) {
        this.mContext = context;
    }

    @Override
    public void action(int actionCode, Object object) {
        fireEvent(actionCode, object);
    }

    @Override
    public List<BasicNameValuePair> setParams() {
        return null;
    }

    @Override
    public String getRequestUrl() {
        return Urls.getAccountRegisterUrl();
    }

    @Override
    public void onDestroy() {
        if (mHttpRequest != null) {
            mHttpRequest.abort();
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public void loadData(Object... objs) {
        params = (List<BasicNameValuePair>) objs[0];
        mHttpRequest =
                new HttpRequest(mContext, UrlManager.COLUMN_DOMAIN_ACCOUNT, getRequestUrl(), params, this);
        mHttpRequest.setDataParseAdapter(new AccountRegisterParser());
        MyTask.runInBackground(mHttpRequest, true);
    }

}
